package com.netty.pro.netty.http;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author xuzn
 * @ClassName: NettyHttpServerInitializer
 * @ProjectName netty-pro
 * @date 2020/3/11/21:47
 */
public class NettyHttpServerInitializer extends ChannelInitializer<SocketChannel> {
  @Override
  protected void initChannel(SocketChannel ch) throws Exception {
    // 向管道加入处理器
    // 得到管道
    ChannelPipeline pipeline = ch.pipeline();
    // 加入编解码
    // 加入一个netty提供的httpServerCodec
    // HttpServerCodec->netty提供的基于http的编解码器
    // HttpServerCodec-->HttpObjectDecoder
    pipeline.addLast("httpServerCodec", new HttpServerCodec());
    // 增加自定义的处理器
    pipeline.addLast("nettyHttpServerHandler", new NettyHttpServerHandler());
    System.out.println("ok...");
  }
}
